// 3. VtpGoodsMapperPageSearch.java - 商品Mapper
package com.lizheng.yunservice.travel.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lizheng.yunservice.travel.doamin.VtpGoodsPageSearch;
import com.lizheng.yunservice.travel.doamin.bo.VtpGoodsQueryBoPageSearch;
import com.lizheng.yunservice.travel.doamin.vo.VtpGoodsVoPageSearch;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface VtpGoodsMapperPageSearch extends BaseMapper<VtpGoodsPageSearch> {

    @Select("<script>" +
            "SELECT " +
            "  g.goods_id, " +
            "  g.title, " +
            "  g.introduction, " +
            "  g.logo_url, " +
            "  g.background_img_url, " +
            "  g.origin_img_url, " +
            "  g.video_url, " +
            "  g.prod_place, " +
            "  g.longitude, " +
            "  g.latitude, " +
            "  g.goods_sku, " +
            "  g.description, " +
            "  DATE_FORMAT(g.part_year, '%Y-%m-%d') AS part_year, " +
            "  g.category_id, " +
            "  g.sold_num, " +
            "  g.stock_num, " +
            "  g.show_status, " +
            "  g.oringinal_price, " +
            "  g.sales_price, " +
            "  g.likes_num, " +
            "  g.collect_num, " +
            "  g.view_num, " +
            "  g.forward_num, " +
            "  g.prepared_num, " +
            "  g.recommend, " +
            "  DATE_FORMAT(g.recommend_time, '%Y-%m-%d %H:%i:%s') AS recommend_time, " +
            "  g.comment_num, " +
            "  g.comment_score, " +
            "  g.good_mark_num, " +
            "  g.common_mark_num, " +
            "  g.bad_mark_num, " +
            "  DATE_FORMAT(g.create_time, '%Y-%m-%d %H:%i:%s') AS createTime, " +
            "  DATE_FORMAT(g.update_time, '%Y-%m-%d %H:%i:%s') AS updateTime, " +
            "  c.category_name " +
            "FROM vtp_goods g " +
            "LEFT JOIN vtp_goods_category c ON g.category_id = c.category_id " +
            "WHERE g.delete_flag = 0 " +
            "<if test='bo.categoryId != null'>" +
            "  AND g.category_id = #{bo.categoryId} " +
            "</if>" +
            "<if test='bo.recommend != null'>" +
            "  AND g.recommend = #{bo.recommend} " +
            "</if>" +
            "<if test='bo.title != null and bo.title != \"\"'>" +
            "  AND g.title LIKE CONCAT('%', #{bo.title}, '%') " +
            "</if>" +
            "<if test='bo.showStatus != null'>" +
            "  AND g.show_status = #{bo.showStatus} " +
            "</if>" +
            "</script>")
    Page<VtpGoodsVoPageSearch> selectAppPage(Page<VtpGoodsVoPageSearch> page, @Param("bo") VtpGoodsQueryBoPageSearch bo);
}